package com.itheima.advance.reflect.demo04;

import java.lang.reflect.Method;

public class ReflectDemo02 {

    public static void main(String[] args) throws Exception {

        Class<?> studentClass = Class.forName("com.itheima.advance.reflect.demo04.Student");
        Method function1 = studentClass.getDeclaredMethod("function1");
        Student student = (Student) studentClass.newInstance();
        function1.invoke(student);
        System.out.println("----------------------");

        Method function2 = studentClass.getDeclaredMethod("function2", String.class);
        function2.invoke(student, "lanzhan");
        System.out.println("-------------------------");

        Method function3 = studentClass.getDeclaredMethod("function3");
        String string = (String) function3.invoke(student);
        System.out.println(string);

        Method function4 = studentClass.getDeclaredMethod("function4", String.class);
        String lanyuan = (String) function4.invoke(student, "lanyuan");
        System.out.println(lanyuan);

        Method show = studentClass.getDeclaredMethod("show");
        show.setAccessible(true);
        show.invoke(student);
    }
}
